package com.ruoyi.job.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.job.api.RemoteJobService;
import com.ruoyi.job.api.domain.SysJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 定时任务降级处理
 *
 * @author j.zh
 */
@Component
public class RemoteJobFallbackFactory implements FallbackFactory<RemoteJobService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteJobFallbackFactory.class);

    @Override
    public  RemoteJobService create(Throwable throwable)
    {
        log.error("定时任务服务调用失败:{}", throwable.getMessage());
        return new RemoteJobService()
        {
            @Override
            public AjaxResult add(@RequestBody SysJob job)
            {
                return AjaxResult.error("创建定时任务失败:" + throwable.getMessage());
            }

        };
    }
}
